package com.weilele.leisure.time.ui.dialog


import android.os.Bundle
import android.view.View
import com.weilele.base.library.BaseBindingPopupWindow
import com.weilele.leisure.time.databinding.PopupWindowSpeedBinding
import com.weilele.leisure.time.ui.holder.SingleTextHolder
import com.weilele.mvvm.adapter.refreshList
import com.weilele.mvvm.utils.activity.dip
import com.weilele.mvvm.utils.activity.getActivity
import com.weilele.mvvm.utils.android_r.fullScreen
import com.weilele.mvvm.utils.android_r.isPortraitScreen


class SpeedPopupWindow : BaseBindingPopupWindow<PopupWindowSpeedBinding>() {
    companion object {
        fun show(view: View, onClick: (data: Float) -> Unit): SpeedPopupWindow {
            return SpeedPopupWindow().apply {
                itemClick = onClick
                width = dip(100)
                showAsDropTopOrBottom(view, isGravityEnd = true)
            }
        }
    }

    private var itemClick: ((position: Float) -> Unit)? = null
    private val speeds = mutableListOf(
        Pair("倍速1.0", 1f),
        Pair("倍速1.5", 1.5f),
        Pair("倍速2.0", 2f),
        Pair("倍速3.0", 3f),
        Pair("倍速4.0", 4f),
    )

    override fun initUi(savedInstanceState: Bundle?) {
        super.initUi(savedInstanceState)
        mBinding.root.adapter = SingleTextHolder.toAdapter().apply {
            refreshList(speeds.map { it.first }.toMutableList())
            setOnHolderClickListener { holder, clickView ->
                dismiss()
                itemClick?.invoke(speeds[holder.bindingPosition].second)
            }
        }
    }


    override fun getDialogDimAmount(): Float {
        return 1f
    }
}